# Makefile for MFR tasks $Revision: 5622 $
#
# (c) 2003, 2004 ECO_L O G Logistiksysteme GmbH, Wels

# $Id: Makefile 5622 2008-04-28 07:29:57Z mge $
# $Name$

# 6/10/2003, MGE:	created
# 2/18/2004, MGE:	improved
# 6/16/2004, MGE:	adapted for production
# see end of file for revision history!

# use -fPIC for .so

BASEDIR:=.

include Common.mk

BIN = .
export BIN
WARN = -Wall
# voruebergehend deaktiviert CFLAGS = -ggdb $(WARN) -Werror -O0 $(CBASEFLAGS)
CFLAGS = -ggdb $(WARN) -O0 $(CBASEFLAGS)
BASE_LIBS = libold.a libeco.a libmfr.a

REVISION := $(shell LANG=en_US svn info --revision 'COMMITTED' | awk '/Revision:/ { print $$2 }')
RELEASENAME = mfr-$(REVISION).$(MACHINE).tar
RELEASESRCNAME = mfr-$(REVISION).src.tar
DEPLOYNAME = $(RELEASENAME).bz2


DIRECTORIES = l2 lk rt

include Linkfile.mk

ifeq ($(CMAJORVERSION), 2)
CXX += -ftemplate-depth-30

LIBECO_OBJS = \
	Config.o \
	Connection.o \
	Dump.o \
	Error.o \
	Framework.o \
	Option.o \
	parse_config.o \
	parse_tagstring.o \
	Timestamp.o \

# obige Leerzeile NICHT entfernen!
#
LIBMFR_OBJS = \
	OraError.o \
	ProtoTask.o \
	RetroTask.o \
	task_db.o \

# obige Leerzeile NICHT entfernen!
#
LIBOLD_OBJS = \
	config.o \
	Config_old.o \
	dako_sr.o \
	deflag.o \
	deflhm.o \
	defstrat.o \
	deftask.o \
	defwb.o \
	defziel.o \
	lib_debug.o \
	oracle.o \
	tooldbg.o \
	tooldb.o \
	toolmfr.o \
	toolmisc.o \

# obige Leerzeile NICHT entfernen!
#
CEXTRAFLAGS = -DCRAP
else
LIBECO_OBJS = \
	AttributeList.o \
	channel_db.o \
	Channel.o \
	Config.o \
	Connection.o \
	Coordinate.o \
	DbConfig.o \
	Device.o \
	Dump.o \
	dynamic_sql.o \
	DynSql.o \
	Error.o \
	File.o \
	Framework.o \
	Graph.o \
	Option.o \
	OraChannel.o \
	parse_config.o \
	parse_logger.o \
	parse_tagstring.o \
	Permutation.o \
	Resource.o \
	Signal.o \
	Timer.o \
	Timestamp.o \
	Tracer.o \

# obige Leerzeile NICHT entfernen!
#
LIBMFR_OBJS = \
	Cargo.o \
	Crate.o \
	DbTask.o \
	IAction.o \
	ICommand.o \
	Info.o \
	Logger.o \
	Message.o \
	ModalTask.o \
	OraChannelListener.o \
	OraError.o \
	ProtoTask.o \
	RetroTask.o \
	SQLCommandInvoker.o \
	Status.o \
	task_db.o \
	Task.o \

# obige Leerzeile NICHT entfernen!
#
LIBOLD_OBJS = \
	config.o \
	Config_old.o \
	dako_sr.o \
	deflag.o \
	deflhm.o \
	defstrat.o \
	deftask.o \
	defwb.o \
	defziel.o \
	lib_debug.o \
	oracle.o \
	tooldbg.o \
	tooldb.o \
	toolmfr.o \
	toolmisc.o \

# obige Leerzeile NICHT entfernen!
#
endif
ifeq ($(MACHINE), x86_64)
# CEXTRAFLAGS += -DKEIN_L2
endif
CFLAGS += $(CEXTRAFLAGS)
CXXFLAGS = $(CFLAGS)

#PROC_FILES = $(shell ls -1 *.pc)
LEX_FILES = $(shell ls -1 *.l)
TEMP_FILES = $(LEX_FILES:.l=.c) $(LIBOLD_OBJS) $(LIBECO_OBJS) $(LIBMFR_OBJS)
POFILES = $(shell ls -1 po/*.po)
POAUTOSRC := $(shell grep -l "[^_]_ *([^)]" *.c *.h *.cpp) $(shell ls -1 scripts/*.sh scripts/*.awk)
PO_C_SRC := $(shell grep -l "[^_]_ *([^)]" *.pc)
PO_SH_SRC = scripts/dako
POSOURCES = $(POAUTOSRC) $(PO_C_SRC) $(PO_SH_SRC)

.INTERMEDIATE:	$(TEMP_FILES)

DEPLOY = \
	$(RBGKOMBMPLUS_OBJS) \
	$(TASK_OBJS) \
	$(TASK_LIBS) \
	convert \
	libeco.a \
	libmfr.a \
	libold.a \
	link.scr \
	Linkfile.mk \
	po/*.po \
	provide \
	use_xml.mk \

SOURCE = \
	l2/*.h l2/*.c l2/*.cpp l2/Makefile l2/cif/api/*.c l2/cif/api/Makefile l2/cif/inc/*.h l2/cif/usr-inc/*.h \
	lk/*.h lk/*.cpp lk/*.pc lk/Makefile \
	rt/*.h rt/*.cpp rt/*.pc rt/Makefile \
	*.cpp \
	*.h \
	*.pc \
	*.c \
	Makefile \
	Linkfile.mk \
	Common.mk \
	*.cfg \
	*.css \
	parse* \
	convert \
	use_xml.sh \
	msgformat.sh \
	parse_out.sh \
	checkpc.sh \
	provide \
	link.scr.sed \

SCRIPTS = \
	auxiliary/* \
	*.awk \
	cp_debug \
	dako \
	dako* \
	dbg2html \
	*.env \
	etc/bridger.cfg \
	etc/dako.cfg \
	gcore.sh \
	lager.sql \
	mfs.sh \
	prog*.sh \
	rennta* \
	setConfig.env \
	showTasks.env \
	stel.sh.template \
	*.template \
	vd \
	vl2 \

# obige Leerzeilen NICHT entfernen!
#
ALL_OBJS = \
	$(FT20_OBJS) \
	$(LIBECO_OBJS) \
	$(LIBMFR_OBJS) \
	$(LIBOLD_OBJS) \
	$(TASK_OBJS) \
	
# obige Leerzeilen NICHT entfernen!
#
ifneq ($(CMAJORVERSION), 2)
ALL_OBJS += \
	$(BRIDGER_OBJS) \
	$(MAIN_OBJS) \
	$(MOCKTASK_OBJS) \
	$(RBGKOMBMPLUS_OBJS) \
	$(RBG_OBJS) \
	
# obige Leerzeilen NICHT entfernen!
#	
DEPLOY += $(MAIN_OBJS)
endif

BINARIES = $(TASK_OBJS:%.o=%) rooter rbg lamkoord rbgkombmplus bridger mocktask

distclean:	NODEP = 1
clean:		NODEP = 1

ifneq ($(NODEP), 1) 
DEPENDENCIES := $(ALL_OBJS:.o=.mk)
endif

ifneq ($(CMAJORVERSION), 2)
ifneq ($(MACHINE), x86_64)
DEPENDENCIES += msgformat.mk
endif
endif

DEPENDENCIES += use_xml.mk
DEPENDENCIES += link.scr

msgformat.mk:
	@./msgformat.sh

use_xml.mk:
	@./use_xml.sh

deploy:		$(RELEASENAME)
	@$(RM) -v $(BINARIES)

export RELEASENAME
export RELEASESRCNAME

$(RELEASENAME):	$(DEPLOY) $(SCRIPTS:%=scripts/%)
ifeq ($(shell if [ -e $(DEPLOYNAME) ] ; then echo "YES" ; else echo "NO" ; fi), YES)
	@echo "Deploy will be renamed"
	@mv $(DEPLOYNAME) $(DEPLOYNAME).old
endif
	@echo "TAR	$@"
	@tar cvf $@ $^
	@+$(MAKE) -C l2 deploy
	@bzip2 -f $@

source:		$(RELEASESRCNAME)
$(RELEASESRCNAME): $(SOURCE)
	@echo "TAR	$@"
	@tar cvf $@ $^
	@bzip2 -f $@

update:		mfr-update.tar.bz2

mfr-update.tar.bz2:	$(DEPLOY) $(SCRIPTS:%=scripts/%)
	tar cjf $@ $?

scripts:	scripts.tar.bz2

scripts.tar.bz2:	$(SCRIPTS:%=scripts/%)
	tar cjf $@ $^

clean:		empty
	@$(RM) -v $(TEMP_FILES) $(BINARIES)
	@$(RM) -v $(TASK_LIBS) $(BASE_LIBS)
	@$(RM) -v *.o *.out *.lis *.lst *~
	@make -C l2 clean
	@make -C lk clean
	@make -C rt clean

distclean:  clean
	@echo $(NODEP)
	@$(RM) -v $(DEPENDENCIES)
#	@$(RM) -v msgformat.mk
#	@$(RM) -v use_xml.mk

tags:		*.h *.c *.pc *.cpp clean
	ctags *.cpp *.c *.h --language-force=c *.pc
	etags *.cpp *.c *.h *.pc

TAGS:		tags

doc:		Doxyfile *.h *.c *.pc *.cpp clean
	doxygen
	touch doc
	make -C l2 doc

log:		ChangeLog

ChangeLog:	CVS
	cvs2cl.pl --passwd=/etc/passwd --domain=ecolog.at -T -t -r -b --show-dead --no-times

parse_config.o:	CFLAGS=-ggdb -Wall

parse_fault.o:	CFLAGS=-ggdb -Wall

parse_logger.o:	CFLAGS=-ggdb -Wall

parse_tagstring.o:	CFLAGS=-ggdb -Wall

# ----------- Libraries ------------

#libold.so: 	libold.a($(LIBOLD_OBJS))
#	ld -shared -soname libold.so.1 -o libold.so.1.0 --whole-archive libold.a

#libeco.so: 	libeco.a
#	ld -shared -E -Bdynamic -soname libeco.so.1 -o libeco.so.1.0 --whole-archive libeco.a -lc

#libold.a: 	libold.a($(LIBOLD_OBJS))
#	@echo "AR	$@ up to date"

libold.a:       $(LIBOLD_OBJS)
	@$(AR) rv $@ $^
	@echo "AR       $@ up to date"

libeco.a:	$(LIBECO_OBJS)
	@$(AR) rv $@ $^
	@echo "AR	$@ up to date"

libmfr.a:	$(LIBMFR_OBJS)
	@$(AR) rv $@ $^
	@echo "AR	$@ up to date"

liblamkoord.a: lk
	+@$(MAKE) -C lk

librooter.a:	rt
	+@$(MAKE) -C rt

gtest:		gtest.o libold.a
	$(CC) -o gtest gtest.o -L. -lold -lold -L$(ORACLE_HOME)/lib/ -lclntsh `cat $(ORACLE_HOME)/lib/ldflags`\
	`cat $(ORACLE_HOME)/lib/sysliblist` -ldl -lm

testlib:	testlib.o libold.a
	$(CC) -o testlib testlib.o -L. -lold

deploy:		CFLAGS = -O0 $(CBASEFLAGS) $(CEXTRAFLAGS)

deploy:		CXXFLAGS = $(CFLAGS) $(CEXTRAFLAGS)

locale:     $(POFILES)

.PHONY:	$(DIRECTORIES) link.scr

test:		$(TASK_LIBS)

$(DIRECTORIES): libeco.a libmfr.a libold.a
	@echo "MK   $@/"
	+@make -C $@

$(POFILES): mfr.pot
	@echo -n "UP	$@"
	@msgmerge --update $@ mfr.pot

mfr.pot:    $(POSOURCES)
	@echo "EXT	$@"
	@xgettext --strict -omfr.pot -s -k_ $(POAUTOSRC)
	@xgettext --strict -omfr.pot -s -j -k_ -LC $(PO_C_SRC)
	@xgettext --strict -omfr.pot -s -j -k$$ -LShell $(PO_SH_SRC)

link.scr:
	@svn info  -r 'COMMITTED' 2>&1 | sed -n -f link.scr.sed >link.scr

parse_config.c:	LFLAGS = -Pcfg

parse_logger.c:	LFLAGS = -Plog

parse_tagstring.c:	LFLAGS = -Ptag

parse_fault.c:	LFLAGS = -Pflt

Permutation.o:	CXXFLAGS += -Wno-deprecated

lago:
#	@echo $(DEPENDENCIES)
#	@echo $(TEMP_FILES)
#	@echo $(CFLAGS)
#	@echo $(TASKS)
#	@echo $(TASK_OBJS)
	@echo $(MACHINE)
#	@echo $(POSOURCES)
#	@echo $(DEPLOY)
#	@echo $(BINARIES)
#	@echo $($$)
	@echo $(REVISION)
	@echo $(RELEASENAME)
	@echo $(RELEASESRCNAME)
	@echo $(CC)

DEPEND_FLAG = -MM

ansidyn1.o:	ansidyn1.pc
	@echo "Compile ansidyn1... " $<
	@proc config=mfr.cfg mode=ansi iname=$< oname=$*_tmp.c >$*.out
	@$(CC) $(CFLAGS) -c -o $@ $*_tmp.c
	@$(RM) $*_tmp.c

dynamic_sql.o: dynamic_sql.pc dynamic_sql.h
	@echo "Compile dynamic_sql..."
	@proc mode=ansi config=mfr.cfg iname=dynamic_sql.pc oname=dynamic_sql_tmp.c >dynamic_sql.out
	@$(CC) $(CFLAGS) -c -o dynamic_sql.o dynamic_sql_tmp.c
	@$(RM) dynamic_sql_tmp.c

#.SUFFIXES: .pc .cpp .c .o .mk .e
.SUFFIXES: .e .o .mk .pc

## han: explizite ausnahme um telbuch mit g++ zu kompilieren
telbuch.o:
	@echo "CC [P]	$<"
	@./checkpc.sh $<
	@proc config=mfrcpp.cfg userid=$(PROCUSER) iname=$< oname=$*_tmp.c >$*.out ; ./parse_out.sh $$? $*
	@$(CXX) $(CXXFLAGS) -c -o $@ $*_tmp.c
	@$(RM) $*_tmp.c

.pc.o:
	@echo "CC [P]	$<"
	@./checkpc.sh $<
	@proc config=mfr.cfg userid=$(PROCUSER) iname=$< oname=$*_tmp.c >$*.out ; ./parse_out.sh $$? $*
	@$(CC) $(CFLAGS) -c -o $@ $*_tmp.c
	@$(RM) $*_tmp.c

.pc.mk:
	@echo "CC [M]	$<"
	@$(CC) $(CFLAGS) -xc $(DEPEND_FLAG) $< > $@

.c.mk:
	@echo "CC [M]	$<"
	@$(CC) $(CFLAGS) $(DEPEND_FLAG) $< > $@

.cpp.mk:
	@echo "CC [M]	$<"
	@$(CXX) $(CXXFLAGS) $(DEPEND_FLAG) $< > $@

#.pc.c:
#	@echo "PROC	$<"
#	@proc config=mfr.cfg iname=$< oname=$@ >$*.out

.l.c:
	@echo "LEX	$<"
	@$(LEX) $(LFLAGS) -t $< > $@

#(%):	%
#	@echo "AR	$@ <-- $<"
#	@$(AR) $(ARFLAGS) $@ $<
#	@$(RM) $<

.pc.s:
	@./checkpc.sh $<
	proc config=mfr.cfg userid=$(PROCUSER) iname=$< oname=tmp.c >$*.out
	$(CC) $(CFLAGS) -S -o $@ tmp.c
	$(RM) tmp.c

.pc.e:
	@./checkpc.sh $<
	proc config=mfr.cfg userid=$(PROCUSER) iname=$< oname=tmp.c >$*.out
	$(CC) $(CFLAGS) -E tmp.c >$@
	$(RM) tmp.c

.c.s:
	$(CC) $(CFLAGS) -S $<

.c.e:
	$(CC) $(CFLAGS) -E $< >$@

.cpp.s:
	$(CXX) $(CXXFLAGS) -S $<

.cpp.e:
	$(CXX) $(CXXFLAGS) -E $< >$@

# dependencies of the various objects and libraries
# from include files as generated further up

ifneq ($@, "clean")
include $(DEPENDENCIES)
endif
